using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;

namespace Medianamik.SubsonicDALProvider.DAL
{
	/// <summary>
	/// Strongly-typed collection for the Publication class.
	/// </summary>
	[Serializable]
	public partial class PublicationCollection : ActiveList<Publication,PublicationCollection> 
	{	   
		public PublicationCollection() {}

	}

	/// <summary>
	/// This is an ActiveRecord class which wraps the medianamik_Publication table.
	/// </summary>
	[Serializable]
	public partial class Publication : ActiveRecord<Publication>, IActiveRecord
	{
		#region .ctors and Default Settings
		
		public Publication()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}

		
		private void InitSetDefaults() { SetDefaults(); }

		
		public Publication(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}

        
		public Publication(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}

		 
		public Publication(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}

		
		protected static void SetSQLProps() { GetTableSchema(); }

		
		#endregion
		
		#region Schema and Query Accessor	
		public static Query CreateQuery() { return new Query(Schema); }

		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}

		}

		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("medianamik_Publication", TableType.Table, DataService.GetInstance("MedianamikProvider"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarPublicationId = new TableSchema.TableColumn(schema);
				colvarPublicationId.ColumnName = "PublicationId";
				colvarPublicationId.DataType = DbType.Guid;
				colvarPublicationId.MaxLength = 0;
				colvarPublicationId.AutoIncrement = false;
				colvarPublicationId.IsNullable = false;
				colvarPublicationId.IsPrimaryKey = true;
				colvarPublicationId.IsForeignKey = false;
				colvarPublicationId.IsReadOnly = false;
				colvarPublicationId.DefaultSetting = @"";
				colvarPublicationId.ForeignKeyTableName = "";
				schema.Columns.Add(colvarPublicationId);
				
				TableSchema.TableColumn colvarNodeId = new TableSchema.TableColumn(schema);
				colvarNodeId.ColumnName = "NodeId";
				colvarNodeId.DataType = DbType.Guid;
				colvarNodeId.MaxLength = 0;
				colvarNodeId.AutoIncrement = false;
				colvarNodeId.IsNullable = false;
				colvarNodeId.IsPrimaryKey = false;
				colvarNodeId.IsForeignKey = true;
				colvarNodeId.IsReadOnly = false;
				colvarNodeId.DefaultSetting = @"";
				
					colvarNodeId.ForeignKeyTableName = "medianamik_Node";
				schema.Columns.Add(colvarNodeId);
				
				TableSchema.TableColumn colvarDateStartOfPublication = new TableSchema.TableColumn(schema);
				colvarDateStartOfPublication.ColumnName = "DateStartOfPublication";
				colvarDateStartOfPublication.DataType = DbType.DateTime;
				colvarDateStartOfPublication.MaxLength = 0;
				colvarDateStartOfPublication.AutoIncrement = false;
				colvarDateStartOfPublication.IsNullable = false;
				colvarDateStartOfPublication.IsPrimaryKey = false;
				colvarDateStartOfPublication.IsForeignKey = false;
				colvarDateStartOfPublication.IsReadOnly = false;
				colvarDateStartOfPublication.DefaultSetting = @"";
				colvarDateStartOfPublication.ForeignKeyTableName = "";
				schema.Columns.Add(colvarDateStartOfPublication);
				
				TableSchema.TableColumn colvarDateEndOfPublication = new TableSchema.TableColumn(schema);
				colvarDateEndOfPublication.ColumnName = "DateEndOfPublication";
				colvarDateEndOfPublication.DataType = DbType.DateTime;
				colvarDateEndOfPublication.MaxLength = 0;
				colvarDateEndOfPublication.AutoIncrement = false;
				colvarDateEndOfPublication.IsNullable = true;
				colvarDateEndOfPublication.IsPrimaryKey = false;
				colvarDateEndOfPublication.IsForeignKey = false;
				colvarDateEndOfPublication.IsReadOnly = false;
				colvarDateEndOfPublication.DefaultSetting = @"";
				colvarDateEndOfPublication.ForeignKeyTableName = "";
				schema.Columns.Add(colvarDateEndOfPublication);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["MedianamikProvider"].AddSchema("medianamik_Publication",schema);
			}

		}

		#endregion
		
		#region Props
		
		  
		[XmlAttribute("PublicationId")]
		public Guid PublicationId 
		{
			get { return GetColumnValue<Guid>(Columns.PublicationId); }

			set { SetColumnValue(Columns.PublicationId, value); }

		}

		  
		[XmlAttribute("NodeId")]
		public Guid NodeId 
		{
			get { return GetColumnValue<Guid>(Columns.NodeId); }

			set { SetColumnValue(Columns.NodeId, value); }

		}

		  
		[XmlAttribute("DateStartOfPublication")]
		public DateTime DateStartOfPublication 
		{
			get { return GetColumnValue<DateTime>(Columns.DateStartOfPublication); }

			set { SetColumnValue(Columns.DateStartOfPublication, value); }

		}

		  
		[XmlAttribute("DateEndOfPublication")]
		public DateTime? DateEndOfPublication 
		{
			get { return GetColumnValue<DateTime?>(Columns.DateEndOfPublication); }

			set { SetColumnValue(Columns.DateEndOfPublication, value); }

		}

		
		#endregion
		
		
			
		
		#region ForeignKey Properties
		
		/// <summary>
		/// Returns a Node ActiveRecord object related to this Publication
		/// 
		/// </summary>
		public Medianamik.SubsonicDALProvider.DAL.Node Node
		{
			get { return Medianamik.SubsonicDALProvider.DAL.Node.FetchByID(this.NodeId); }

			set { SetColumnValue("NodeId", value.NodeId); }

		}

		
		
		#endregion
		
		
		
		//no ManyToMany tables defined (0)
		
        
        
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(Guid varPublicationId,Guid varNodeId,DateTime varDateStartOfPublication,DateTime? varDateEndOfPublication)
		{
			Publication item = new Publication();
			
			item.PublicationId = varPublicationId;
			
			item.NodeId = varNodeId;
			
			item.DateStartOfPublication = varDateStartOfPublication;
			
			item.DateEndOfPublication = varDateEndOfPublication;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(Guid varPublicationId,Guid varNodeId,DateTime varDateStartOfPublication,DateTime? varDateEndOfPublication)
		{
			Publication item = new Publication();
			
				item.PublicationId = varPublicationId;
			
				item.NodeId = varNodeId;
			
				item.DateStartOfPublication = varDateStartOfPublication;
			
				item.DateEndOfPublication = varDateEndOfPublication;
			
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		#endregion
        
        
        
        #region Typed Columns
        
        
        public static TableSchema.TableColumn PublicationIdColumn
        {
            get { return Schema.Columns[0]; }

        }

        
        
        
        public static TableSchema.TableColumn NodeIdColumn
        {
            get { return Schema.Columns[1]; }

        }

        
        
        
        public static TableSchema.TableColumn DateStartOfPublicationColumn
        {
            get { return Schema.Columns[2]; }

        }

        
        
        
        public static TableSchema.TableColumn DateEndOfPublicationColumn
        {
            get { return Schema.Columns[3]; }

        }

        
        
        
        #endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string PublicationId = @"PublicationId";
			 public static string NodeId = @"NodeId";
			 public static string DateStartOfPublication = @"DateStartOfPublication";
			 public static string DateEndOfPublication = @"DateEndOfPublication";
						
		}

		#endregion
		
		
		
	}

}

